package com.jiangwz.boot.starter;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author jiangwz
 * @create 2019/8/27.
 */
@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties(value = {PersonProperties.class})
public class PersonAutoConfiguration {

    private final PersonProperties personProperties;

    public PersonAutoConfiguration(PersonProperties personProperties) {
        this.personProperties = personProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    public PersonService jwzPersonService(){
        return new PersonService(this.personProperties.getName());
    }
}
